package com.jugheadzhou.auth.core.websocket.config;

import com.jugheadzhou.auth.core.websocket.WebSocketManager;
import com.jugheadzhou.auth.core.websocket.heart.WebSocketHeartCheckTask;
import com.jugheadzhou.auth.core.websocket.manager.MemWebSocketManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * 内存管理websocket配置
 *
 * @author jugheadzhou
 */
@Configuration
public class WebSocketConfig {

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Bean
    @ConditionalOnMissingBean(WebSocketManager.class)
    public WebSocketManager webSocketManager() {
        return new MemWebSocketManager();
    }

    /**
     * 引入WebSocket任务bean
     *
     * @return
     */
    @Bean
    @ConditionalOnBean(WebSocketManager.class)
    public WebSocketHeartCheckTask webSocketScheduled() {
        return new WebSocketHeartCheckTask();
    }
}